package com.googlecode.battleofendor.synchroniation;

import com.googlecode.battleofendor.synchroniation.messages.Ping;

public class HostPlayer extends Player {
	
	public long currentTimeMillis() {
		return System.currentTimeMillis();
	}
	
	public void addConnection(final Connection connection) {
		// Zeit synchronisieren:
		// Ping senden und Antwortzeit messen.
		// Differenz erneut senden.
		
		Ping ping = new Ping();
		ping.ping(this);
		connection.writeObject(ping);
		System.out.println("Host: Ping sent");
		
		Ping pong = (Ping) connection.readObject();
		connection.writeObject(pong.back(this));
		
		// Threads erzeugen
		new Thread(updateMirrorPool(connection)).start();
		new Thread(publishOwnPool(connection)).start();
		System.out.println("Host is running ...");
	}
}
